//
//  HJViewModel.m
//  project
//
//  Created by yefei on 2019/7/20.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJViewModel.h"
#import "HJVideoModel.h"

@interface HJViewModel()
// 页码
@property (nonatomic, assign) NSInteger page;

@end

@implementation HJViewModel


//下拉加载接口
- (void)refreshNewListWithSuccess:(void(^)(NSArray *list))success failure:(void(^)(NSString *error))failure {
    self.page = 1;
    NSString * url = [Api stringByAppendingString:MatchApi];
    [HJHttpTool get:url params:@{@"pageCurrent":@(self.page)} success:^(HJResponeds *result) {
        NSArray <HJVideoModel*>*array = [NSArray yy_modelArrayWithClass:[HJVideoModel class] json:result.data];
        !success ? : success(array);
    } failure:^(id result) {
        failure(result);
    }];
}

//上拉加载接口
- (void)refreshMoreListWithSuccess:(void(^)(NSArray *list))success failure:(void(^)(NSString *error))failure {
    self.page++;
    NSString * url = [Api stringByAppendingString:MatchApi];
    [HJHttpTool get:url params:@{@"pageCurrent":@(self.page)} success:^(HJResponeds *result) {
        NSArray <HJVideoModel*>*array = [NSArray yy_modelArrayWithClass:[HJVideoModel class] json:result.data];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            !success ? : success(array);
        });
    } failure:^(id result) {
         failure(result);
    }];
}

// 点赞接口
-(void)loadPraiseDataWorkWithParams:(NSDictionary *)params Success:(successBlock)success failure:(failureBlock)failure {
    NSString * url = [Api stringByAppendingString:PraiseApi];
    [HJHttpTool post:url params:params success:^(HJResponeds *result) {
        !success ? : success();
    } failure:^(id result) {
        failure(result);
    }];
}

// 获取评论接口
-(void)loadReViewDataWorkWithParams:(NSDictionary *)params Success:(void(^)(NSArray *list, NSString *totalPage))sucess failure:(failureBlock)failure {
    
}

// 动态评论
-(void)loadReviewSubMitDataWorkWithParams:(NSDictionary *)params success:(void(^)(id data))success failure:(failureBlock)failure {
    NSString * url = [Api stringByAppendingString:ReviewSubmitApi];
    [HJHttpTool post:url params:params success:^(HJResponeds *result) {
        HJCommentModel * commentModel = [HJCommentModel yy_modelWithDictionary:result.data];
        !success ? : success(commentModel);
    } failure:^(id result) {
        failure(result);
    }];
}

// 关注接口
-(void)loadConcernDataWithParams:(NSDictionary *)param success:(successBlock)success failure:(failureBlock)failure {
    NSString * url = [Api stringByAppendingString:ConcernApi];
    [HJHttpTool post:url params:param success:^(HJResponeds *result) {
        !success ? : success();
    } failure:^(id result) {
        failure(result);
    }];
}

@end
